package com.ws.components.loader
{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	
	public class PictureLoader extends Loader implements ILoader
	{
		private var _callbackFun:Function;
		private var _url:String;
		private var _lc:*;
		
		public function PictureLoader(aUrl:String)
		{
			super();
			this._url = aUrl;
			this.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
			this.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onError);
		}
		
		public function loadUrl(aCallbackFun:Function=null):void{
			_callbackFun = aCallbackFun;			
			var req:URLRequest= new URLRequest(_url);
			super.load(req);
		}
		
		public function get loaderContent():*{
			return this._lc;
		}
		
		private function callBack():void{
			if(_callbackFun!=null){
				_callbackFun(this);
			}
		}
		
		private function onError(event:IOErrorEvent):void{
			
		}
		
		private function onLoadComplete(event:Event):void{
			this._lc = this.content;
			this.unload();
			callBack();
		}
	}
}